/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author karenAndy
 */
import java.util.Scanner;

public class Driver {

    public static void main(String[] args) {

        int op = 0, newElement;

        Scanner input = new Scanner(System.in);

        Set sets = new Set();
        String newSet;

        //Main Menu
        do {
            System.out.println("\t\t.::: Operations with Sets :::.");
            System.out.println();
            System.out.println("1. Add elements to the set");
            //System.out.println("2. Remove elements from the set");
            System.out.println("2. Union");
            System.out.println("3. Intersection");
            System.out.println("4. Show a set");
            System.out.println("5. Exit");


            System.out.print("\nEnter the option you want to: ");
            try {
                op = input.nextInt();
            } catch (Exception e) {
                System.out.print("\nInvalid option");
                op = 5;
            }
            //Defensive programming
            while (op < 1 || op > 5) {
                System.out.print("\nInvalid option. Enter the option you want to: ");
                op = input.nextInt();
            }

            switch (op) {
                case 1:
                    System.out.print("Choose a set A or B: ");
                    newSet = input.next().toUpperCase();
                    System.out.print("Enter an element: ");
                    newElement = input.nextInt();

                    try {
                        if (newSet.equals("A")) {
                            sets.Add("A", newElement);
                        } else if (newSet.equals("B")) {
                            sets.Add("B", newElement);
                        }
                    } catch (Exception e) {
                        System.out.println("The required set does not exist");
                    }
                    break;


                /*case 2:
                System.out.print("Choose a set A or B: ");
                newSet = input.next().toUpperCase();
                System.out.print("\nEnter an element: ");
                newElement = input.nextInt();

                if (newSet.equals("A")) {
                sets.Remove("B", newElement);
                } else if (newSet.equals("B")) {
                sets.Remove("B", newElement);
                } else if (!newSet.equals("A") || !newSet.equals("B") || !newSet.equals("C")) {
                System.out.println("The required set does not exist");
                }
                break;
                 */
                case 2:
                    sets.Union();
                    if (sets.ShowSet("C").isEmpty()) {
                        System.out.println("The set is empty");
                    } else {
                        System.out.println(sets.ShowSet("C"));
                    }
                    break;


                case 3:
                    sets.Intersection();
                    if (sets.ShowSet("C").isEmpty()) {
                        System.out.println("The set is empty");
                    } else {
                        System.out.println(sets.ShowSet("C"));
                    }
                    break;

                case 4:
                    System.out.print("Choose a set A, B or C: ");
                    newSet = input.next().toUpperCase();

                    if (newSet.equals("A")) {
                        if (sets.ShowSet("A").compareTo(" ")<0) {
                            System.out.println("The set is empty");
                        } else {
                            System.out.println(sets.ShowSet("A"));
                        }
                    } else if (newSet.equals("B")) {
                        System.out.println(sets.ShowSet("B"));
                    } else if (newSet.equals("C")) {
                        System.out.println(sets.ShowSet("C"));
                    } else if (!newSet.equals("A") || !newSet.equals("B") || !newSet.equals("C")) {
                        System.out.println("The required set does not exist");
                    }
                    break;

                case 5:
                    System.out.println("\t\t.::: Thanks for using this program :::.");
                    break;
            }
        } while (op != 5);
    }
}
